var db = openDatabase("eroese", "1.1", "This save eroese infomation", 200000*3);
var log = '';
//保存 糟糕圈出现过的名字 
function friendcache_onerr(tx, error){
	if(error.code != 5){
		//alert(error.message+' id='+error.code);
	}else{ //没有的话就新建friendcache表
		db.transaction(function(tx) {
			tx.executeSql("CREATE TABLE friendcache (id REAL UNIQUE, name TEXT)",[],
			null,friendcache_onerr);
		});
	}
}
function save_name(_name) {
	var num = Math.round(Math.random() * 10000); 
	db.transaction(function(tx) {
		tx.executeSql("SELECT * FROM friendcache WHERE name = ?",[_name],function(tx, result){
			var len = result.rows.length;
			if(len == 0){
				tx.executeSql(
				"INSERT INTO friendcache (id,name) VALUES (?, ?)",[num,_name],null,friendcache_onerr);
			}
		},friendcache_onerr);
	});
}

function read_name(_n,callback){
	db.transaction(function(tx){
		tx.executeSql("SELECT * FROM friendcache WHERE name LIKE ?",[_n+'%'],callback,friendcache_onerr);
	});
}

function empty_name(){
		db.transaction(function(tx){
		tx.executeSql("DELETE FROM friendcache",[],null,friendcache_onerr);
	});
}
